<!-- 正文开始 -->
<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-card-body">
      <!-- 头部操作栏 -->
      <form class="layui-form">
        <div class="layui-form lay-header">
          <div class="toolbar">
            <div class="layui-form-item lay-query-content">
              <div class="lay-query-box">
                <div class="query-lt">
                  <div class="layui-inline">
                    <label class="layui-form-label">订单来源：</label>
                    <div class="layui-input-inline">
                      <select name="orderSource">
                        <option value="">请选择订单来源</option>
                        <option value="staff">自主录入/员工录入</option>
                        <option value="platform">云端制造/平台指派</option>
                        <option value="agent">渠道录入/代理商录入</option>
                        <option value="customer">云端智采/客户直接委派</option>
                      </select>
                    </div>
                  </div>
                  <div class="layui-inline">
                    <label class="layui-form-label">订单状态：</label>
                    <div class="layui-input-inline">
                      <select name="status">
                        <option value="">请选择订单状态</option>
                        <option value="pending">待提交</option>
                        <option value="accept">待受理</option>
                        <option value="review">待评审</option>
                        <option value="refuse">不接单</option>
                        <option value="offer">待报价</option>
                        <option value="tosign">待签约</option>
                        <option value="signed">已签约</option>
                        <option value="finish">已完成</option>
                        <option value="over">已关闭</option>
                      </select>
                    </div>
                  </div>
                  <div class="layui-inline">
                    <label class="layui-form-label">客户名称：</label>
                    <div class="layui-input-inline">
                      <input name="customerName" class="layui-input" type="text" placeholder="请输入客户名称" />
                    </div>
                  </div>
                  <div class="layui-inline">
                    <label class="layui-form-label">订单编号：</label>
                    <div class="layui-input-inline">
                      <input name="code" class="layui-input" type="text" placeholder="请输入订单编号" />
                    </div>
                  </div>
                </div>
                <div class="query-rt">
                  <div class="layui-inline">
                    <button type="button" class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog" lay-submit type="button">查询</button>
                    <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit type="button">重置</button>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="lay-btn-rows">
            <div class="lay-btn-box">
              <div class="lay-btn-lt">
                <button id="inquiryOrderInformationBtnAdd" class="layui-btn icon-btn color-reseda" type="button">添加询价订单</button>
              </div>
              <div class="lay-btn-rt"></div>
            </div>
          </div>
        </div>
      </form>
      <!-- 表格 -->
      <table class="layui-table" id="orderTable" lay-filter="orderTable"></table>
    </div>
  </div>
</div>

<style>
  .open-details-box::-webkit-scrollbar {
    width: 0 !important;
  }

  div[lay-id="inquiryOrderOfferTable"] .layui-form,
  div[lay-id="inquiryOrderOfferTable"] .layui-table-box,
  div[lay-id="inquiryOrderOfferTable"] .layui-table-body,
  div[lay-id="inquiryOrderOfferTable"] .layui-table-cell,
  div[lay-id="inquiryOrderInformationTable"] .layui-form,
  div[lay-id="inquiryOrderInformationTable"] .layui-table-box,
  div[lay-id="inquiryOrderInformationTable"] .layui-table-body,
  div[lay-id="inquiryOrderInformationTable"] .layui-table-cell,
  div[lay-id="inquiryOrderExamineTable"] .layui-form,
  div[lay-id="inquiryOrderExamineTable"] .layui-table-box,
  div[lay-id="inquiryOrderExamineTable"] .layui-table-body,
  div[lay-id="inquiryOrderExamineTable"] .layui-table-cell,
  div[lay-id="inquiryOrderExamineOrderProReviewTable"] .layui-form,
  div[lay-id="inquiryOrderExamineOrderProReviewTable"] .layui-table-box,
  div[lay-id="inquiryOrderExamineOrderProReviewTable"] .layui-table-body,
  div[lay-id="inquiryOrderExamineOrderProReviewTable"] .layui-table-cell,
  div[lay-id="inquiryReviewResultTable"] .layui-form,
  div[lay-id="inquiryReviewResultTable"] .layui-table-box,
  div[lay-id="inquiryReviewResultTable"] .layui-table-body,
  div[lay-id="inquiryReviewResultTable"] .layui-table-cell {
    overflow: visible;
    padding: 0 1px;
  }

  div[lay-id="inquiryOrderOfferTable"] .layui-table-cell,
  div[lay-id="inquiryOrderExamineOrderProReviewTable"] .layui-table-cell,
  div[lay-id="inquiryReviewResultTable"] .layui-table-cell {
    overflow: visible;
    padding: 10px;
  }

  div[lay-id="inquiryOrderOfferTable"] .layui-table-cell,
  div[lay-id="inquiryReviewResultTable"] .layui-table-cell,
  div[lay-id="inquiryOrderExamineOrderProReviewTable"] .layui-table-cell,
  div[lay-id="inquiryOrderInformationTable"] .layui-table-cell,
  div[lay-id="inquiryOrderDetailsTable"] .layui-table-cell,
  div[lay-id="inquiryOrderExamineTable"] .layui-table-cell,
  div[lay-id="inquiryOrderQuotationRecordDetailsTable"] .layui-table-cell {
    height: auto;
    overflow: visible;
  }

  /*inquiryOrderOfferForm*/
  form[lay-filter="inquiryOrderDetailsForm"] .layui-row label,
  form[lay-filter="inquiryOrderExamineForm"] .layui-row label,
  form[lay-filter="inquiryOrderInformationForm"] .layui-row label,
  .inquiryOrderBox .layui-row label {
    width: 90px;
    padding: 9px;
  }

  .inquiryOrderBox .layui-form-item .layui-inline,
  form[lay-filter="inquiryOrderDetailsForm"] .layui-form-item .layui-inline,
  form[lay-filter="inquiryOrderExamineForm"] .layui-form-item .layui-inline,
  form[lay-filter="inquiryOrderInformationForm"] .layui-form-item .layui-inline {
    margin-right: 0;
  }

  form[lay-filter="inquiryOrderInformationForm"] .layui-form-item .layui-form-mid,
  form[lay-filter="inquiryOrderDetailsForm"] .layui-form-item .layui-form-mid {
    padding: 9px 0 0 !important;
  }

  form[lay-filter="inquiryOrderInformationForm"] xm-select > .xm-body .xm-search-input {
    padding-left: 10px;
  }

  form[lay-filter="inquiryOrderInformationForm"] xm-select > .xm-body .xm-search > i {
    right: 20px;
  }

  .inquiryOrderBox .layui-input-inline input[readonly],
  .inquiryOrderBox .layui-input-inline input[readonly]:hover,
  .inquiryOrderBox .layui-input-inline input[readonly]:focus,
  form[lay-filter="inquiryOrderDetailsForm"] input[readonly],
  form[lay-filter="inquiryOrderDetailsForm"] input[readonly]:hover,
  form[lay-filter="inquiryOrderDetailsForm"] input[readonly]:focus,
  form[lay-filter="inquiryOrderExamineForm"] .layui-inline input[readonly],
  form[lay-filter="inquiryOrderExamineForm"] .layui-inline input[readonly]:hover,
  form[lay-filter="inquiryOrderExamineForm"] .layui-inline input[readonly]:focus {
    border-color: transparent !important;
    outline-color: transparent;
  }

  .inquiryOrderReviewForm-title {
    width: 100%;
  }

  .inquiryOrderReviewForm-title .title {
    display: inline-block;
    font-size: 16px;
    font-weight: bold;
    color: #333333;
    line-height: 19px;
    position: relative;
    padding: 6px 0 19px 0;
  }

  .inquiryOrderReviewForm-title .title:after {
    content: "";
    display: block;
    position: absolute;
    left: 0;
    bottom: 0;
    width: calc(100% + 6px);
    height: 3px;
    background: #0a8b0a;
  }

  .line {
    width: 100%;
    height: 1px;
    background-color: #f8f8f8;
  }

  [lay-filter="contractForm"] .layui-form-label,
  [lay-filter="contractChangeRecordForm"] .layui-form-label {
    width: 100px;
  }

  [lay-filter="contractForm"] .layui-input-block,
  [lay-filter="contractChangeRecordForm"] .layui-input-block {
    margin-left: 130px;
  }

  .preview {
    cursor: pointer;
    float: left;
  }

  .download {
    cursor: pointer;
    float: right;
  }

  .file-a {
    font-size: 12px;
    word-break: break-all;
    text-overflow: ellipsis;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    margin-top: 5px;
  }

  .info_row {
    height: 30px;
    line-height: 30px;
  }

  .attachments {
    cursor: pointer;
    display: block;
    float: left;
    overflow: hidden;
    text-align: center;
    padding: 0 10px;
    width: 100px;
  }
</style>

<!-- 表格操作列 -->
<!--pending待提交、accept待受理、review待评审、offer待报价、tosign待签约、over已关闭-->
<script type="text/html" id="orderTableBar">
  <a class="layui-btn layui-btn-xs color-green" lay-event="details">详情</a>
  <!-- {{# if(d.status=="pending"){  }} -->
  <a class="layui-btn layui-btn-xs color-green" lay-event="edit">修改</a>
  <a class="layui-btn layui-btn-xs color-green" lay-event="idSubmit">确认提交</a>
  <!-- {{# } else{ }} -->
  <!-- {{# if(d.status=="accept"){  }} -->
  <a class="layui-btn layui-btn-xs " lay-event="acceptance">受理/评审</a>
  <!-- {{# } else{ }} -->
  <a class="layui-btn layui-btn-xs " lay-event="acceptance">评审信息</a>
  <!-- {{# } }} -->
  <!-- {{# } }} -->
  <!-- {{# if(['offer'].includes(d.status)){  }} -->
  <a class="layui-btn layui-btn-xs " lay-event="offer">添加报价</a>
  <!-- {{# } }} -->
  <!-- {{# if(['offer','tosign'].includes(d.status)){  }} -->
  <a class="layui-btn layui-btn-xs " lay-event="quotationRecord">报价记录</a>
  <!-- {{# } }} -->
  <!-- {{# if(['tosign','signed'].includes(d.status)){  }} -->
  <a class="layui-btn layui-btn-xs " lay-event="zsOrder">转正式订单</a>
  <!-- {{# } }} -->
</script>

<!--询价订单评审 操作-->
<!--inquiryOrderDetailsReviewBar-->
<script type="text/html" id="inquiryOrderDetailsReviewBar">
  <!-- {{# if(d.finalResult == 'unhandled'){ }} -->
  <a class="layui-btn layui-btn-xs" lay-event="review">评审结果</a>
  <!-- {{# }else{ }} -->
  <a class="layui-btn layui-btn-xs" lay-event="reviewDetails">详情</a>
  <!-- {{# } }} -->
</script>

<!-- 订单物料列表 询价订单评审 -->
<!--inquiryOrderReview-->
<script type="text/html" id="inquiryOrderReviewForm">
  <form lay-filter="inquiryOrderReviewForm" class="layui-form model-form inquiryOrderBox" style="padding: 5px 30px 0 30px;height: calc(100% - 5px);overflow: hidden;">
    <div class="open-details-box" style="height: calc(100% - 75px); padding-top: 20px;overflow: auto">
      <div class="layui-form-item layui-row">
        <input name="id" type="hidden" />
        <div class="layui-inline layui-col-md3">
          <label class="layui-form-label">客户名称:</label>
          <div class="layui-input-inline">
            <input type="text" class="layui-input" name="customerName" readonly />
          </div>
        </div>
        <div class="layui-inline layui-col-md3">
          <label class="layui-form-label">客户联系人:</label>
          <div class="layui-input-inline">
            <input type="text" class="layui-input" name="customerContactsName" readonly />
          </div>
        </div>
        <div class="layui-inline layui-col-md3">
          <label class="layui-form-label">联系人电话:</label>
          <div class="layui-input-inline">
            <input type="text" class="layui-input" name="customerContactsPhone" readonly />
          </div>
        </div>
        <div class="layui-inline layui-col-md3">
          <label class="layui-form-label">交货时间:</label>
          <div class="layui-input-inline">
            <input type="text" class="layui-input" name="deliveryTime" readonly />
          </div>
        </div>
        <div class="layui-inline layui-col-md3">
          <label class="layui-form-label">所属渠道:</label>
          <div class="layui-input-inline">
            <input type="text" class="layui-input" name="channelName" readonly />
          </div>
        </div>
        <div class="layui-inline layui-col-md3">
          <label class="layui-form-label">订单录入人:</label>
          <div class="layui-input-inline">
            <input type="text" class="layui-input" name="orderCreatorName" readonly />
          </div>
        </div>
        <div class="layui-inline layui-col-md3">
          <label class="layui-form-label">所属部门:</label>
          <div class="layui-input-inline">
            <input type="text" class="layui-input" name="departmentName" readonly />
          </div>
        </div>
        <div class="layui-inline layui-col-md3">
          <label class="layui-form-label">提交时间:</label>
          <div class="layui-input-inline">
            <input type="text" class="layui-input" name="createTime" readonly />
          </div>
        </div>
        <div class="layui-inline layui-col-md3">
          <label class="layui-form-label">报价截止时间:</label>
          <div class="layui-input-inline">
            <input type="text" class="layui-input" name="offerEndTime" readonly />
          </div>
        </div>
        <div class="layui-inline layui-col-md3">
          <label class="layui-form-label">报价受理人:</label>
          <div class="layui-input-inline">
            <input type="text" class="layui-input" name="checkerName" readonly />
          </div>
        </div>
      </div>
      <div class="layui-form-item">
        <div class="inquiryOrderReviewForm-title">
          <h3 class="title">订单信息</h3>
        </div>
        <div class="line"></div>
        <table class="layui-table" id="inquiryOrderReviewTable" lay-filter="inquiryOrderReviewTable"></table>
      </div>

      <div class="layui-form-item">
        <div class="inquiryOrderReviewForm-title">
          <h3 class="title">评审环节</h3>
        </div>
        <div class="line"></div>
        <table class="layui-table" id="inquiryReviewLinkTable" lay-filter="inquiryReviewLinkTable"></table>
      </div>

      <div class="layui-form-item">
        <div class="inquiryOrderReviewForm-title">
          <h3 class="title">终审结果</h3>
        </div>
        <div class="line"></div>
        <table class="layui-table" id="inquiryReviewResultTable" lay-filter="inquiryReviewResultTable"></table>
      </div>
    </div>
    <div class="layui-form-item text-right">
      <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
      <button class="layui-btn" lay-filter="inquiryOrderReviewSubmit" lay-submit>保存</button>
    </div>
  </form>
</script>

<!-- 订单物料列表 询价订单报价 -->
<!--inquiryOrderOffer-->
<script type="text/html" id="inquiryOrderOfferForm">
  <form lay-filter="inquiryOrderOfferForm" class="layui-form model-form inquiryOrderBox" style="padding: 5px 30px 0 30px;height: calc(100% - 5px);overflow: hidden;">
    <div class="open-details-box" style="height: calc(100% - 75px); padding-top: 20px;overflow: auto">
      <div class="layui-form-item layui-row">
        <input name="id" type="hidden" />
        <div class="layui-inline layui-col-md3">
          <label class="layui-form-label">客户名称:</label>
          <div class="layui-input-inline">
            <input type="text" class="layui-input" name="customerName" readonly />
          </div>
        </div>
        <div class="layui-inline layui-col-md3">
          <label class="layui-form-label">客户联系人:</label>
          <div class="layui-input-inline">
            <input type="text" class="layui-input" name="customerContactsName" readonly />
          </div>
        </div>
        <div class="layui-inline layui-col-md3">
          <label class="layui-form-label">联系人电话:</label>
          <div class="layui-input-inline">
            <input type="text" class="layui-input" name="customerContactsPhone" readonly />
          </div>
        </div>
        <div class="layui-inline layui-col-md3">
          <label class="layui-form-label">交货时间:</label>
          <div class="layui-input-inline">
            <input type="text" class="layui-input" name="deliveryTime" readonly />
          </div>
        </div>
        <div class="layui-inline layui-col-md3">
          <label class="layui-form-label">所属渠道:</label>
          <div class="layui-input-inline">
            <input type="text" class="layui-input" name="channelName" readonly />
          </div>
        </div>
        <div class="layui-inline layui-col-md3">
          <label class="layui-form-label">订单录入人:</label>
          <div class="layui-input-inline">
            <input type="text" class="layui-input" name="orderCreatorName" readonly />
          </div>
        </div>
        <div class="layui-inline layui-col-md3">
          <label class="layui-form-label">所属部门:</label>
          <div class="layui-input-inline">
            <input type="text" class="layui-input" name="departmentName" readonly />
          </div>
        </div>
        <div class="layui-inline layui-col-md3">
          <label class="layui-form-label">提交时间:</label>
          <div class="layui-input-inline">
            <input type="text" class="layui-input" name="createTime" readonly />
          </div>
        </div>
        <div class="layui-inline layui-col-md3">
          <label class="layui-form-label">报价截止时间:</label>
          <div class="layui-input-inline">
            <input type="text" class="layui-input" name="offerEndTime" readonly />
          </div>
        </div>
        <div class="layui-inline layui-col-md3">
          <label class="layui-form-label">报价受理人:</label>
          <div class="layui-input-inline">
            <input type="text" class="layui-input" name="checkerName" readonly />
          </div>
        </div>
      </div>
      <div class="layui-form-item">
        <table class="layui-table" id="inquiryOrderOfferTable" lay-filter="inquiryOrderOfferTable"></table>
      </div>
    </div>
    <div class="layui-form-item text-right">
      <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
      <button class="layui-btn" lay-filter="inquiryOrderOfferSubmit" lay-submit>保存</button>
    </div>
  </form>
</script>

<!--订单物料列表 报价记录  操作-->
<!--inquiryOrderQuotationRecordBar-->
<script type="text/html" id="inquiryOrderQuotationRecordBar">
  <!-- {{# if(!d.whetherFinal){ }} -->
  <a class="layui-btn layui-btn-xs" lay-event="details">修改</a>
  <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="final">设为终版</a>
  <!-- {{# }else{ }} -->
  <a class="layui-btn layui-btn-xs" lay-event="details">详情</a>
  <!-- {{# } }} -->
</script>

<!--订单物料列表 报价记录  详情-->
<!--inquiryOrderQuotationRecordDetails-->
<script type="text/html" id="inquiryOrderQuotationRecordDetailsForm">
  <form
    lay-filter="inquiryOrderQuotationRecordDetailsForm"
    class="layui-form model-form inquiryOrderBox"
    style="padding: 5px 30px 0 30px;height: calc(100% - 5px);overflow: hidden;">
    <div class="open-details-box" style="height: calc(100% - 75px); padding-top: 20px;overflow: auto">
      <div class="layui-form-item layui-row">
        <input name="id" type="hidden" />
        <div class="layui-inline layui-col-md3">
          <label class="layui-form-label">客户名称:</label>
          <div class="layui-input-inline">
            <input type="text" class="layui-input" name="customerName" readonly />
          </div>
        </div>
        <div class="layui-inline layui-col-md3">
          <label class="layui-form-label">客户联系人:</label>
          <div class="layui-input-inline">
            <input type="text" class="layui-input" name="customerContactsName" readonly />
          </div>
        </div>
        <div class="layui-inline layui-col-md3">
          <label class="layui-form-label">联系人电话:</label>
          <div class="layui-input-inline">
            <input type="text" class="layui-input" name="customerContactsPhone" readonly />
          </div>
        </div>
        <div class="layui-inline layui-col-md3">
          <label class="layui-form-label">交货时间:</label>
          <div class="layui-input-inline">
            <input type="text" class="layui-input" name="deliveryTime" readonly />
          </div>
        </div>
        <div class="layui-inline layui-col-md3">
          <label class="layui-form-label">所属渠道:</label>
          <div class="layui-input-inline">
            <input type="text" class="layui-input" name="channelName" readonly />
          </div>
        </div>
        <div class="layui-inline layui-col-md3">
          <label class="layui-form-label">订单录入人:</label>
          <div class="layui-input-inline">
            <input type="text" class="layui-input" name="orderCreatorName" readonly />
          </div>
        </div>
        <div class="layui-inline layui-col-md3">
          <label class="layui-form-label">所属部门:</label>
          <div class="layui-input-inline">
            <input type="text" class="layui-input" name="departmentName" readonly />
          </div>
        </div>
        <div class="layui-inline layui-col-md3">
          <label class="layui-form-label">提交时间:</label>
          <div class="layui-input-inline">
            <input type="text" class="layui-input" name="createTime" readonly />
          </div>
        </div>
        <div class="layui-inline layui-col-md3">
          <label class="layui-form-label">报价截止时间:</label>
          <div class="layui-input-inline">
            <input type="text" class="layui-input" name="offerEndTime" readonly />
          </div>
        </div>
        <div class="layui-inline layui-col-md3">
          <label class="layui-form-label">报价受理人:</label>
          <div class="layui-input-inline">
            <input type="text" class="layui-input" name="checkerName" readonly />
          </div>
        </div>
      </div>
      <div class="layui-form-item">
        <table class="layui-table" id="inquiryOrderQuotationRecordDetailsTable" lay-filter="inquiryOrderQuotationRecordDetailsTable"></table>
      </div>
    </div>
    <div class="layui-form-item text-right">
      <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
      <button class="layui-btn" lay-filter="inquiryOrderQuotationRecordDetailsSubmit" lay-submit>保存</button>
    </div>
  </form>
</script>

<!--合同-->
<!--inquiryOrderContract-->
<script type="text/html" id="inquiryOrderContractForm">
  <form lay-filter="inquiryOrderContractForm" class="layui-form model-form" style="padding: 5px 30px 0 30px;height: calc(100% - 5px);overflow: hidden;">
    <div class="open-details-box" style="height: calc(100% - 75px); padding-top: 20px;overflow: auto">
      <div class="layui-form-item">
        <div class="layui-inline">
          <button class="layui-btn color-reseda" id="contractBtnAdd" type="button">添加合同</button>
        </div>
      </div>
      <div class="layui-form-item">
        <table class="layui-table" id="inquiryOrderContractFormTable" lay-filter="inquiryOrderContractFormTable"></table>
      </div>
    </div>
    <div class="layui-form-item text-right">
      <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
    </div>
  </form>
</script>

<!-- 合同表格操作列 -->
<script type="text/html" id="contractTableBar">
  <a class="layui-btn layui-btn-xs" lay-event="view">详情</a>
  <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="changeRecord">变更记录</a>
</script>

<script type="text/html" id="contractTablePreservationBar">
  <a class="layui-btn layui-btn-xs" lay-event="preservation">保存</a>
</script>

<!--合同附件-->
<script type="text/html" id="viewAttachmentBar">
  <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="viewAttachment">查看附件</a>
</script>

<!-- 查看附件 -->
<script type="text/html" id="viewAttachmentHtml">
  <div id="example1" style="height: 100%;"></div>
</script>

<!-- 终版弹窗 -->
<script type="text/html" id="contractFinalForm">
  <form lay-filter="contractFinalForm" class="layui-form model-form">
    <input name="id" type="hidden" />
    <div class="layui-form-item">
      <label class="layui-form-label"><span style="color: red">*</span>交货时间</label>
      <div class="layui-input-block">
        <input name="deliveryTime" id="deliveryTimeFina" placeholder="请选择交货时间" type="text" class="layui-input" readonly lay-verify="required" required />
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label"><span style="color: red">*</span>合同存放地点</label>
      <div class="layui-input-block">
        <input name="address" placeholder="请输入合同存放地点" type="text" class="layui-input" lay-verify="required" required />
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label"><span style="color: red">*</span>合同保管员</label>
      <div class="layui-input-block">
        <select name="keeper" lay-verify="required" required lay-search></select>
      </div>
    </div>
    <div class="layui-form-item text-right">
      <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
      <button class="layui-btn" lay-filter="contractFinalFormSubmit" lay-submit>确认终版</button>
    </div>
  </form>
</script>

<!-- js部分 -->

<script type="text/javascript" src="../../../admin/assets/js/pdfobject.min.js"></script>
<script type="text/javascript" src="../../../admin/assets/js/jsencrypt.min.js"></script>

<script>
  //在Jquery里格式化Date日期时间数据
  function timeStamp2String(time) {
    var datetime = new Date(time);
    var year = datetime.getFullYear();
    var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
    var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
    var hour = datetime.getHours() < 10 ? "0" + datetime.getHours() : datetime.getHours();
    var minute = datetime.getMinutes() < 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
    var second = datetime.getSeconds() < 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
    // return year + "-" + month + "-" + date+" "+hour+":"+minute+":"+second;
    return year + "年" + month + "月" + date + "日";
  }

  layui.use(["layer", "form", "table", "admin", "laydate", "upload", "laytpl"], function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var config = layui.config;
    var admin = layui.admin;
    var upload = layui.upload;
    let laydate = layui.laydate;
    let laytpl = layui.laytpl;
    let InquiryOrderDetailsFormData = {};

    form.render("select");
    // 渲染表格
    let insTb = table.render({
      elem: "#orderTable",
      url: config.base + "enterprise/sell/admin/order/list",
      // url: config.base + 'enterprise/sell/admin/trialOrder/list',
      toolbar: true,
      defaultToolbar: ["filter"],
      page: true,
      cellMinWidth: 100,
      cols: [
        [
          { type: "numbers", title: "序号" },
          { field: "code", align: "center", sort: false, title: "订单编号" },
          { field: "orderSourceDesc", align: "center", sort: false, title: "订单来源" },
          { field: "customerName", align: "center", sort: false, title: "客户名称" },
          // , {field: 'orderTypeDesc', align: 'center',sort: false, title: '订单类型'}
          { field: "proQuantity", align: "center", sort: false, title: "物料数量", width: 90 },
          { field: "amount", align: "center", sort: false, title: "订单总金额", width: 100 },
          { field: "statusDesc", align: "center", sort: false, title: "订单状态", width: 90 },
          { field: "creatorName", align: "center", sort: false, title: "添加人" },
          { field: "createTime", align: "center", sort: false, title: "添加时间" },
          { align: "center", toolbar: "#orderTableBar", title: "操作", width: 400 }
        ]
      ],
      done: function (res, curr, count) {}
    });

    function openOrderForm(data, event = "") {
      admin.formOpen({
        area: ["90%", "85%"],
        offset: ["50px", "5%"],
        title: "订单详情",
        style: "font-size: 20px;",
        path: "components/sell/orderForm.html",
        success: function () {
          parentData.data = data;
          parentData.eventName = event;
        }
      });
    }

    // 工具条点击事件
    table.on("tool(orderTable)", async function (obj) {
      let data = obj.data;
      if (obj.event === "edit") {
        //修改
        admin.req("enterprise/sell/admin/order/detail/" + data.id, {}, function (res) {
          if (res.code == 200) {
            openOrderForm(res.data, "edit");
          }
        });
      } else if (obj.event === "del") {
        // 删除
        doDelete(obj);
      } else if (obj.event === "confirmSubmission") {
        doConfirm(data, 1);
      } else if (obj.event === "details") {
        admin.req("enterprise/sell/admin/order/detail/" + data.id, {}, function (res) {
          if (res.code == 200) {
            openOrderForm(res.data, "details");
          }
        });
      } else if (obj.event === "idSubmit") {
        // 确认提交
        layer.confirm(
          "确定要提交吗？",
          {
            offset: "65px",
            skin: "layui-layer-admin"
          },
          function (i) {
            admin.req(
              "enterprise/sell/admin/order/submit",
              { id: data.id, type: 1 },
              function (res) {
                layer.closeAll("loading");
                if (res.code == 200) {
                  layer.msg(res.msg, { icon: 1 });
                  layer.closeAll("page");
                  table.reload("orderTable");
                } else {
                  layer.msg(res.msg, { icon: 2 });
                }
              },
              "POST"
            );
          }
        );
      } else if (obj.event === "acceptance") {
        // 受理
        admin.req("enterprise/sell/admin/order/detail/" + data.id, {}, function (res) {
          if (res.code == 200) {
            openOrderForm(res.data, "acceptance");
          }
        });
        // InquiryOrderDetailsFormData = '';
        // InquiryOrderDetailsFormData = data;
        // showInquiryOrderDetailsForm(data, 'acceptance', '订单物料列表');
      } else if (obj.event === "review") {
        // 评审
        InquiryOrderDetailsFormData = "";
        InquiryOrderDetailsFormData = data;
        showInquiryOrderDetailsForm(data, "review", "订单评审");
      } else if (obj.event === "closure") {
        // 结案
        doConfirm(data, 7);
      } else if (obj.event === "offer") {
        //报价
        admin.req("enterprise/sell/admin/order/detail/" + data.id, {}, function (res) {
          if (res.code == 200) {
            openOrderForm(res.data, "offer");
          }
        });
      } else if (obj.event === "quotationRecord") {
        // 报价记录
        // InquiryOrderDetailsFormData = '';
        // InquiryOrderDetailsFormData = data;
        // showInquiryOrderQuotationRecordForm(data)
        admin.req("enterprise/sell/admin/orderOffer/list", { orderId: data.id }, function (res) {
          admin.formOpen({
            area: ["90%", "85%"],
            offset: ["50px", "5%"],
            title: "报价记录",
            style: "font-size: 20px;",
            path: "components/sell/orderOfferForm.html",
            success: function () {
              parentData.data = res.data;
              parentData.id = data.id;
              parentData.eventName = "quotationRecord";
              console.log(res.data);
            }
          });
        });
      } else if (obj.event === "contract") {
        // 合同
        InquiryOrderDetailsFormData = "";
        InquiryOrderDetailsFormData = data;
        showInquiryOrderContractForm(data);
      } else if (obj.event === "zsOrder") {
        admin.req("enterprise/sell/admin/order/detail/" + data.id, {}, function (res) {
          if (res.code == 200) {
            openOrderForm(res.data, "zsOrder");
          }
        });
        // console.log(await admin.req ('enterprise/sell/admin/orderOffer/list'))
        // layer.confirm(
        //   "确定要转正式订单吗？",
        //   {
        //     offset: "65px",
        //     skin: "layui-layer-admin"
        //   },
        //   function (i) {
        //     admin.req(
        //       "enterprise/sell/admin/orderOffer/toZSOrder",
        //       { id: data.id },
        //       function (res) {
        //         layer.closeAll("loading");
        //         if (res.code == 200) {
        //           layer.msg(res.msg, { icon: 1 });
        //           layer.closeAll("page");
        //           table.reload("orderTable");
        //         } else {
        //           layer.msg(res.msg, { icon: 2 });
        //         }
        //       },
        //       "POST"
        //     );
        //   }
        // );
      }
    });

    //监听排序
    table.on("sort(orderTable)", function (obj) {
      table.reload("orderTable", {
        initSort: obj,
        where: {
          sort: obj.field,
          order: obj.type
        }
      });
    });

    // 搜索
    form.on("submit(formSubSearchLog)", function (data) {
      insTb.reload({ where: data.field, page: { curr: 1 } }, "data");
    });

    // 重置搜索
    form.on("submit(resets)", function (data) {
      $(".lay-header").find("select").val("");
      $(".lay-header").find("input").val("");
      var field = data.field;
      for (let key in field) {
        field[key] = "";
      }
      insTb.reload({ where: field, page: { curr: 1 } }, "data");
      return false;
    });

    // 添加按钮点击事件
    $("#inquiryOrderInformationBtnAdd").click(function () {
      showInquiryOrderInformation();
      return false;
    });

    // 显示编辑弹窗
    function showEditModel(data) {
      admin.open({
        type: 1,
        area: "900px",
        offset: "65px",
        title: data ? "修改订单" : "添加订单",
        content: $("#orderForm").html(),
        success: function () {
          if (data) {
            var option = $("form select[name='orderSource']").find("option");
            layui.each(option, function (index, item) {
              if (data.orderSource == item.text) {
                data.orderSource = item.value;
              }
            });
          }

          if (data) {
            var option = $("form select[name='orderType']").find("option");
            layui.each(option, function (index, item) {
              if (data.orderType == item.text) {
                data.orderType = item.value;
              }
            });
          }

          if (data) {
            var option = $("form select[name='status']").find("option");
            layui.each(option, function (index, item) {
              if (data.status == item.text) {
                data.status = item.value;
              }
            });
          }

          form.val("orderForm", data);
          // 表单提交事件
          form.on("submit(orderFormSubmit)", function (d) {
            layer.load(2);
            admin.req(
              data ? "enterprise/sell/admin/order/update" : "enterprise/sell/admin/order/add",
              d.field,
              function (res) {
                layer.closeAll("loading");
                if (res.code == 200) {
                  layer.msg(res.msg, { icon: 1 });
                  table.reload("orderTable");
                  layer.closeAll("page");
                } else {
                  layer.msg(res.msg, { icon: 2 });
                }
              },
              data ? "PUT" : "POST"
            );
            return false;
          });
        }
      });
    }

    // 删除
    function doDelete(obj) {
      layer.confirm(
        "确定要删除吗？",
        {
          offset: "65px",
          skin: "layui-layer-admin"
        },
        function (i) {
          layer.close(i);
          layer.load(2);
          admin.req(
            "enterprise/sell/admin/order/" + obj.data.id,
            {},
            function (res) {
              layer.closeAll("loading");
              if (res.code == 200) {
                layer.msg(res.msg, { icon: 1 });
                obj.del();
              } else {
                layer.msg(res.msg, { icon: 2 });
              }
            },
            "DELETE"
          );
        }
      );
    }

    // 导出excel
    $("#orderBtnExport").click(function () {
      var checkRows = table.checkStatus("orderTable");
      if (checkRows.data.length == 0) {
        layer.msg("请选择要导出的数据", { icon: 2 });
      } else {
        table.exportFile(insTb.config.id, checkRows.data, "xls");
      }
    });

    // 添加询价订单信息
    function showInquiryOrderInformation(data) {
      openOrderForm({}, "add");
      // admin.formOpen({
      //     area: ['80%', '85%'],
      //     offset: ['10%', '10%'],
      //     title: data ? '修改订单' : '添加订单',
      //     style: 'font-size: 20px;',
      //     path: 'components/sell/orderForm.html'
      // });
    }

    // 删除
    function showInquiryOrderInformationListDoDelete(obj) {
      admin.req("enterprise/sell/admin/orderPro/delBatch?ids=" + obj, {}, function (res) {}, "DELETE");
    }

    // 渲染下拉框数据
    function loadSelectHtml(data, tips, htmltarget, type, formName) {
      let html = " <option value>" + tips + "</option>";
      if (!data || data == null) {
        return;
      }
      for (let i = 0; i < data.length; i++) {
        if (type === 1) {
          html += `<option value='${data[i].id}'>${data[i].customerName}</option>`;
        } else if (type === 2) {
          html += `<option value='${data[i].id}' phone='${data[i].telephone}'>${data[i].name}</option>`;
        } else if (type === 3) {
          html += `<option value='${data[i].id}'>${data[i].name}</option>`;
        } else if (type === 4) {
          html += `<option value='${data[i].id}'>${data[i].username}</option>`;
        }
      }

      $("form[lay-filter='" + formName + "']  select[name='" + htmltarget + "']").html(html);
      form.render("select");
    }

    // 上传图片
    function uploadImg(_elem, pathId, inputId) {
      upload.render({
        elem: "#" + _elem,
        url: config.upload_url + "upload",
        data: {},
        accept: "file",
        exts: "jpg|png|RAR|zip|pdf|txt|doc|docx|xls|xlsx|ppt|pptx",
        headers: { Authorization: "Bearer " + config.getToken() },
        done: function (res) {
          if (res.code == 200) {
            layer.msg(res.msg || "上传成功", { icon: 1 });
            let imagUrl = res.data.url;
            $("#" + pathId).html('<img src="' + imagUrl + '" style="height: 35px;"/>');
            $("#" + inputId).val(imagUrl);
          } else if (res.code == 502) {
            return location.replace("admin/login.html");
          } else {
            layer.msg(res.msg || "上传失败", { icon: 2 });
          }
        }
      });
    }

    //获取审批人和业务员
    function getUsers() {
      admin.req(
        "user/admin/user/list",
        { limit: 9999 },
        function (res) {
          if (res.code == 200) {
            var html = '<option value="">请选择</option>';
            for (var k = 0; k < res.data.length; k++) {
              html += '<option value="' + res.data[k].id + '">' + res.data[k].username + "</option>";
            }
            $("form select[name='approver']").html(html);
            $("form select[name='salesmanId']").html(html);
            form.render("select");
          } else {
            layer.msg("获取审批人失败", { icon: 2, time: 1000 });
          }
        },
        "GET"
      );
    }

    //获取代理商
    function getAgentInfo() {
      admin.req(
        "enterprise/sell/admin/agent/list?status=1",
        { limit: 9999 },
        function (res) {
          if (res.code == 200) {
            var html = '<option value="">请选择</option>';
            for (var k = 0; k < res.data.length; k++) {
              html += '<option value="' + res.data[k].id + '">' + res.data[k].name + "</option>";
            }
            $("form select[name='selAgtId']").html(html);
            form.render("select");
          } else {
            layer.msg("获取代理商失败", { icon: 2, time: 1000 });
          }
        },
        "GET"
      );
    }

    // 公共方法修改订单数据
    function doConfirm(data, _type) {
      layer.confirm(
        "确定要提交吗？",
        {
          offset: "65px",
          skin: "layui-layer-admin"
        },
        function (i) {
          layer.close(i);
          layer.load(2);
          admin.req(
            "enterprise/sell/admin/order/submit",
            { id: data.id, type: _type },
            function (res) {
              layer.closeAll("loading");
              if (res.code == 200) {
                layer.msg(res.msg, { icon: 1 });
                layer.closeAll("page");
                table.reload("orderTable");
              } else {
                layer.msg(res.msg, { icon: 2 });
              }
            },
            "POST"
          );
        }
      );
    }

    // 询价订单审核
    function showInquiryOrderExamineForm(data, _type) {
      let inquiryOrderExaminePop = admin.open({
        type: 1,
        area: ["1450px", "750px"],
        offset: "75px",
        title: _type == "examine" ? "订单审核" : "订单详情",
        content: $("#inquiryOrderExamineForm").html(),
        success: function () {
          let inquiryOrderExamineOrderProReviewTbData = []; // 评审环节本地列表数据
          let reviewProcessIdData = []; // 评审环节下拉框数据
          form.val("inquiryOrderExamineForm", InquiryOrderDetailsFormData);
          let inquiryOrderExamineTb = table.render({
            elem: "#inquiryOrderExamineTable",
            data: [data],
            page: false,
            cellMinWidth: 100,
            cols: [
              [
                { field: "customerSkuItem", title: "客户物料编号" },
                { field: "customerSkuName", title: "物料名称" },
                { field: "customerSpecCode", title: "规格码" },
                {
                  field: "orderProEnclosureList",
                  title: "附件",
                  templet: (d) => {
                    let orderProEnclosureListHtml = "";
                    d.orderProEnclosureList.forEach((item, index) => {
                      orderProEnclosureListHtml += '<a href="' + item.fileUrl + ' target="_blank">' + item.fileName + "</a></br />";
                    });
                    return orderProEnclosureListHtml;
                  }
                },
                { field: "proUnitName", title: "单位" },
                { field: "quantity", title: "数量" },
                { field: "proRemark", title: "备注" },
                {
                  align: "center",
                  title: "操作",
                  templet: (d) => {
                    let selectHTML = "";
                    selectHTML += '<select name="status" lay-filter="status" lay-verify="required">';
                    selectHTML += '<option value="">请选择</option>';
                    selectHTML += `<option value="accepted" ${d.status == "accepted" ? 'selected=""' : ""}>受理</option>`;
                    selectHTML += `<option value="refuse" ${d.status == "refuse" ? 'selected=""' : ""}>不受理</option>`;
                    selectHTML += "</select>";
                    return selectHTML;
                  }
                }
              ]
            ],
            done: function (res, curr, count) {
              form.on("select(status)", function (data) {
                if (data.value == "accepted") {
                  $("#inquiryOrderExamineOrderProReviewBox").show({ duration: 300 });
                } else {
                  $("#inquiryOrderExamineOrderProReviewBox").hide({ duration: 300 });
                  inquiryOrderExamineOrderProReviewTbData = [];
                  table.reload("inquiryOrderExamineOrderProReviewTable", { data: inquiryOrderExamineOrderProReviewTbData });
                }
              });
              if (_type == "" + "" + "") {
                $('[lay-filter="status"]').attr("disabled", "disabled");
                $("#inquiryOrderExamineOrderProReviewAdd").hide();
                $('button[lay-filter="inquiryOrderExamineSubmit"]').hide();
                $("#inquiryOrderExamineOrderProReviewBox").show();
                form.render("select");
              }
            }
          });

          // 请求 评审环节下拉框数据
          admin.reqSync(
            "enterprise/sell/admin/order/findReview",
            { type: InquiryOrderDetailsFormData.orderType },
            (res) => {
              if (res.code === 200) {
                reviewProcessIdData = [];
                reviewProcessIdData = res.data;
              }
            },
            "get"
          );

          if (_type == "" + "" + "") {
            data.orderProReviewList.forEach((item, index) => {
              item.reviewProcessIdData = reviewProcessIdData;
              admin.reqSync(
                "enterprise/sell/admin/orderReviewProcessCompany/getRoleData",
                { processId: item.reviewProcessId },
                (res) => {
                  if (res.code === 200) {
                    item.reviewPostIdData = res.data;
                  }
                },
                "get"
              );
              admin.reqSync(
                "user/admin/user/list",
                { postId: item.reviewPostId },
                (res) => {
                  if (res.code === 200) {
                    item.reviewerIdData = res.data;
                  }
                },
                "get"
              );

              inquiryOrderExamineOrderProReviewTbData.push(item);
            });
          } else {
            // 添加评审环节
            $("#inquiryOrderExamineOrderProReviewAdd").click(function () {
              let inquiryOrderExamineOrderProReviewTbDataObj = {};
              inquiryOrderExamineOrderProReviewTbDataObj.index = inquiryOrderExamineOrderProReviewTbData.length;
              inquiryOrderExamineOrderProReviewTbDataObj.reviewProcessIdData = reviewProcessIdData;
              inquiryOrderExamineOrderProReviewTbDataObj.reviewProcessId = "";
              inquiryOrderExamineOrderProReviewTbDataObj.reviewProcessName = "";
              inquiryOrderExamineOrderProReviewTbDataObj.reviewPostIdData = [];
              inquiryOrderExamineOrderProReviewTbDataObj.reviewPostId = "";
              inquiryOrderExamineOrderProReviewTbDataObj.reviewPostName = "";
              inquiryOrderExamineOrderProReviewTbDataObj.reviewerIdData = [];
              inquiryOrderExamineOrderProReviewTbDataObj.reviewerId = "";
              inquiryOrderExamineOrderProReviewTbDataObj.reviewerName = "";
              inquiryOrderExamineOrderProReviewTbDataObj.reviewEndTime = "";
              inquiryOrderExamineOrderProReviewTbDataObj.remark = "";
              inquiryOrderExamineOrderProReviewTbData.push(inquiryOrderExamineOrderProReviewTbDataObj);
              table.reload("inquiryOrderExamineOrderProReviewTable", { data: inquiryOrderExamineOrderProReviewTbData });
            });
          }

          let inquiryOrderExamineOrderProReviewTb = table.render({
            elem: "#inquiryOrderExamineOrderProReviewTable",
            data: inquiryOrderExamineOrderProReviewTbData,
            page: false,
            cellMinWidth: 100,
            height: 500,
            cols: [
              [
                {
                  field: "reviewProcessId",
                  title: "评审环节",
                  width: "200",
                  templet: (d) => {
                    let selectHTML = "";
                    selectHTML += '<select name="reviewProcessId" lay-filter="reviewProcessId" lay-verify="required">';
                    selectHTML += '<option value="">评审环节</option>';
                    d.reviewProcessIdData.forEach((item) => {
                      if (d.reviewProcessId == item.id) {
                        selectHTML += '<option value="' + item.id + '" selected="">' + item.name + "</option>";
                      } else {
                        selectHTML += '<option value="' + item.id + '">' + item.name + "</option>";
                      }
                    });
                    selectHTML += "</select>";
                    return selectHTML;
                  }
                },
                {
                  field: "reviewPostId",
                  title: "评审岗位",
                  width: "200",
                  templet: (d) => {
                    let selectHTML = "";
                    selectHTML += '<select name="reviewPostId" lay-filter="reviewPostId" lay-verify="required">';
                    selectHTML += '<option value="">评审岗位</option>';
                    d.reviewPostIdData.forEach((item) => {
                      if (d.reviewPostId == item.id) {
                        selectHTML += '<option value="' + item.id + '" selected="">' + item.name + "</option>";
                      } else {
                        selectHTML += '<option value="' + item.id + '">' + item.name + "</option>";
                      }
                    });
                    selectHTML += "</select>";
                    return selectHTML;
                  }
                },
                {
                  field: "reviewerId",
                  title: "评审人员",
                  width: "200",
                  templet: (d) => {
                    let selectHTML = "";
                    selectHTML += '<select name="reviewerId" lay-filter="reviewerId" lay-verify="required">';
                    selectHTML += '<option value="">评审人员</option>';
                    d.reviewerIdData.forEach((item) => {
                      if (d.reviewerId == item.id) {
                        selectHTML += '<option value="' + item.id + '" selected="">' + item.username + "</option>";
                      } else {
                        selectHTML += '<option value="' + item.id + '">' + item.username + "</option>";
                      }
                    });
                    selectHTML += "</select>";
                    return selectHTML;
                  }
                },
                {
                  field: "reviewEndTime",
                  title: "截至时间",
                  width: "200",
                  templet: (d) => {
                    let reviewEndTimeHtml = '<input class="layui-input" id="reviewEndTime' + d.index + '" name="reviewEndTime" value="' + d.reviewEndTime + '"/>';
                    return reviewEndTimeHtml;
                  }
                },
                {
                  field: " remark",
                  title: "评审备注",
                  width: "400",
                  templet: (d) => '<input type="text" name="reviewRemark" class="layui-input" value="' + d.remark + '">'
                },
                _type == "" + "" + ""
                  ? ""
                  : {
                      align: "center",
                      toolbar: "#inquiryOrderInformationFormBar",
                      title: "操作"
                    }
              ]
            ],
            done: function (res, curr, count) {
              for (let i = 0; i < count; i++) {
                laydate.render({
                  elem: "#reviewEndTime" + res.data[i].index,
                  type: "datetime",
                  index: res.data[i].index,
                  done: function (value, date) {
                    inquiryOrderExamineOrderProReviewTbData[this.index].reviewEndTime = value;
                  }
                });
              }
              if (_type == "" + "" + "") {
                $('div[lay-id="inquiryOrderExamineOrderProReviewTable"] input').attr("disabled", "disabled");
                $('div[lay-id="inquiryOrderExamineOrderProReviewTable"] select').attr("disabled", "disabled");
                form.render("select");
              }
            }
          });

          // 工具条点击事件
          table.on("tool(inquiryOrderExamineOrderProReviewTable)", function (obj) {
            let data = obj.data;
            if (obj.event === "delete") {
              //删除
              inquiryOrderExamineOrderProReviewTbData.splice(obj.tr.index(), 1);
              table.reload("inquiryOrderExamineOrderProReviewTable", { data: inquiryOrderExamineOrderProReviewTbData });
            }
          });

          form.on("select", function (data) {
            if ($(data.elem).attr("name") == "reviewProcessId") {
              if (data.value && data.value != "") {
                // 请求 评审岗位下拉框数据
                admin.reqSync(
                  "enterprise/sell/admin/orderReviewProcessCompany/getRoleData",
                  { processId: data.value },
                  (res) => {
                    if (res.code === 200) {
                      inquiryOrderExamineOrderProReviewTbData[$(data.elem).parents("tr").index()].reviewPostIdData = res.data;
                    }
                  },
                  "get"
                );
              } else {
                inquiryOrderExamineOrderProReviewTbData[$(data.elem).parents("tr").index()].reviewPostIdData = [];
                inquiryOrderExamineOrderProReviewTbData[$(data.elem).parents("tr").index()].reviewerIdData = [];
              }
              inquiryOrderExamineOrderProReviewTbData[$(data.elem).parents("tr").index()].reviewProcessId = data.value;
              inquiryOrderExamineOrderProReviewTbData[$(data.elem).parents("tr").index()].reviewProcessName = data.elem[data.elem.selectedIndex].text;
              table.reload("inquiryOrderExamineOrderProReviewTable", { data: inquiryOrderExamineOrderProReviewTbData });
            } else if ($(data.elem).attr("name") == "reviewPostId") {
              // 请求 评审人员下拉框数据
              if (data.value && data.value != "") {
                admin.reqSync(
                  "user/admin/user/list",
                  { postId: data.value },
                  (res) => {
                    if (res.code === 200) {
                      inquiryOrderExamineOrderProReviewTbData[$(data.elem).parents("tr").index()].reviewerIdData = res.data;
                    }
                  },
                  "get"
                );
              } else {
                inquiryOrderExamineOrderProReviewTbData[$(data.elem).parents("tr").index()].reviewerIdData = [];
              }
              inquiryOrderExamineOrderProReviewTbData[$(data.elem).parents("tr").index()].reviewPostId = data.value;
              inquiryOrderExamineOrderProReviewTbData[$(data.elem).parents("tr").index()].reviewPostName = data.elem[data.elem.selectedIndex].text;
              table.reload("inquiryOrderExamineOrderProReviewTable", { data: inquiryOrderExamineOrderProReviewTbData });
            } else if ($(data.elem).attr("name") == "reviewerId") {
              inquiryOrderExamineOrderProReviewTbData[$(data.elem).parents("tr").index()].reviewerId = data.value;
              inquiryOrderExamineOrderProReviewTbData[$(data.elem).parents("tr").index()].reviewerName = data.elem[data.elem.selectedIndex].text;
            }
          });

          $("body").delegate("[lay-id='inquiryOrderExamineOrderProReviewTable'] input[name='reviewRemark']", "change", function () {
            if (inquiryOrderExamineOrderProReviewTbData[$(this).parents("tr").index()]) {
              inquiryOrderExamineOrderProReviewTbData[$(this).parents("tr").index()].remark = $(this).val().trim();
            }
          });

          //保存
          form.on("submit(inquiryOrderExamineSubmit)", function (d) {
            let objData = {},
              objDataList = [];
            layer.load(2);
            new Promise((resolve, reject) => {
              inquiryOrderExamineOrderProReviewTbData.forEach((item, index) => {
                objDataList[index] = {};
                objDataList[index].reviewProcessId = item.reviewProcessId;
                objDataList[index].reviewProcessName = item.reviewProcessName;
                objDataList[index].reviewPostId = item.reviewPostId;
                objDataList[index].reviewPostName = item.reviewPostName;
                objDataList[index].reviewerId = item.reviewerId;
                objDataList[index].reviewerName = item.reviewerName;
                objDataList[index].reviewEndTime = item.reviewEndTime;
                objDataList[index].remark = item.remark;
              });
              resolve(objDataList);
            }).then((r) => {
              objData.status = d.field.status;
              objData.id = data.id;
              objData.orderId = InquiryOrderDetailsFormData.id;
              if (d.field.status == "accepted") {
                if (r.length > 0) {
                  objData.orderProReviewList = r;
                } else {
                  layer.msg("请添加评环节", { icon: "2" });
                  layer.closeAll("loading");
                  return false;
                }
              } else {
                objData.orderProReviewList = [];
              }

              admin.req(
                "enterprise/sell/admin/orderPro/update",
                JSON.stringify(objData),
                function (res) {
                  layer.closeAll("loading");
                  if (res.code == 200) {
                    layer.msg(res.msg, { icon: 1 });
                    InquiryOrderDetailsFormData.orderProList.forEach(function (item) {
                      if (item.id == data.id) {
                        item.statusDesc = objData.status == "accepted" ? "已受理" : "不受理";
                        item.status = objData.status;
                        table.reload("inquiryOrderDetailsTable", { data: InquiryOrderDetailsFormData.orderProList });
                      }
                    });
                    table.reload("orderTable");
                    layer.close(inquiryOrderExaminePop);
                  } else {
                    layer.msg(res.msg, { icon: 2 });
                  }
                },
                "PUT",
                true,
                "application/json; charset=utf-8"
              );
            });
            return false;
          });
        }
      });
    }

    // 询价订单 评审
    function showInquiryOrderReviewForm(data, _type) {
      let inquiryOrderReviewPop = admin.open({
        type: 1,
        area: ["1450px", "750px"],
        offset: "75px",
        title: _type == "review" ? "订单评审" : "订单评审详情",
        content: $("#inquiryOrderReviewForm").html(),
        success: function () {
          // 评审环节数据
          let inquiryReviewResultTableData = "";

          form.val("inquiryOrderReviewForm", InquiryOrderDetailsFormData);

          // 物料信息
          let inquiryOrderExamineTb = table.render({
            elem: "#inquiryOrderReviewTable",
            data: [data],
            page: false,
            cellMinWidth: 100,
            cols: [
              [
                { field: "customerSkuItem", title: "客户物料编号" },
                { field: "customerSkuName", title: "客户物料名称" },
                { field: "customerSpecCode", title: "规格码" },
                {
                  field: "orderProEnclosureList",
                  title: "附件",
                  templet: (d) => {
                    let orderProEnclosureListHtml = "";
                    d.orderProEnclosureList.forEach((item, index) => {
                      orderProEnclosureListHtml += '<a href="' + item.fileUrl + ' target="_blank">' + item.fileName + "</a></br />";
                    });
                    return orderProEnclosureListHtml;
                  }
                },
                { field: "proUnitName", title: "单位" },
                { field: "quantity", title: "数量" },
                { field: "proRemark", title: "备注" },
                { field: "statusDesc", title: "状态" }
              ]
            ],
            done: function (res, curr, count) {}
          });

          // 评审环节
          let inquiryReviewLinkTb = table.render({
            elem: "#inquiryReviewLinkTable",
            data: data.orderProReviewList,
            page: false,
            cellMinWidth: 100,
            cols: [
              [
                { field: "reviewProcessName", title: "评审环节" },
                { field: "reviewPostName", title: "评审岗位" },
                { field: "reviewPostName", title: "评审人员" },
                { field: "reviewEndTime", title: "截至时间" },
                { field: "remark", title: "评审备注" },
                { field: "statusDesc", title: "状态" },
                { field: "resultDesc", title: "评审结果" },
                { field: "reviewDesc", title: "结果描述" },
                { field: "reviewTime", title: "评审用时" }
              ]
            ],
            done: function (res, curr, count) {}
          });

          if (_type == "review") {
            inquiryReviewResultTableData = [
              {
                finalResult: "",
                suggestLowestPrice: "",
                suggestPrice: "",
                discountPrice: "",
                offerRemark: ""
              }
            ];
          } else {
            inquiryReviewResultTableData = [data];
          }

          //终审结果
          let inquiryReviewResultTb = table.render({
            elem: "#inquiryReviewResultTable",
            data: inquiryReviewResultTableData,
            page: false,
            cellMinWidth: 100,
            height: 250,
            cols: [
              [
                {
                  field: "finalResult",
                  title: "是否接单",
                  templet: (d) => {
                    let selectHTML = "";
                    selectHTML += '<select name="finalResult" lay-filter="finalResult" lay-verify="required">';
                    selectHTML += '<option value="">是否接单</option>';
                    selectHTML += `<option value="pass" ${d.finalResult == "pass" ? 'selected=""' : ""}>接单</option>`;
                    selectHTML += `<option value="fail" ${d.finalResult == "fail" ? 'selected=""' : ""}>不接单</option>`;
                    selectHTML += "</select>";
                    return selectHTML;
                  }
                },
                {
                  field: "suggestLowestPrice",
                  title: "建议最低单价",
                  templet: (d) => '<input type="text" name="suggestLowestPrice" class="layui-input" value="' + d.suggestLowestPrice + '">'
                },
                {
                  field: "suggestPrice",
                  title: "建议单价",
                  templet: (d) => '<input type="text" name="suggestPrice" class="layui-input" value="' + d.suggestPrice + '">'
                },
                {
                  field: "discountPrice",
                  title: "优惠单价",
                  templet: (d) => '<input type="text" name="discountPrice" class="layui-input" value="' + d.discountPrice + '">'
                },
                {
                  field: "offerRemark",
                  title: "备注说明",
                  templet: (d) => '<input type="text" name="offerRemark" class="layui-input" value="' + d.offerRemark + '">'
                }
              ]
            ],
            done: function (res, curr, count) {
              if (_type == "" + "" + "") {
                $('div[lay-id="inquiryReviewResultTable"] input').attr("disabled", "disabled");
                $('div[lay-id="inquiryReviewResultTable"] select').attr("disabled", "disabled");
                $('button[lay-filter="inquiryOrderReviewSubmit"]').hide();
                form.render("select");
              }
            }
          });

          form.on("select", function (data) {
            if ($(data.elem).attr("name") == "finalResult") {
              inquiryReviewResultTableData[$(data.elem).parents("tr").index()].finalResult = data.value;
            }
          });

          $("body").delegate("[lay-id='inquiryReviewResultTable'] input[name='suggestPrice']", "change", function () {
            if (inquiryReviewResultTableData[$(this).parents("tr").index()]) {
              inquiryReviewResultTableData[$(this).parents("tr").index()].suggestPrice = $(this).val().trim();
            }
          });

          $("body").delegate("[lay-id='inquiryReviewResultTable'] input[name='suggestLowestPrice']", "change", function () {
            if (inquiryReviewResultTableData[$(this).parents("tr").index()]) {
              inquiryReviewResultTableData[$(this).parents("tr").index()].suggestLowestPrice = $(this).val().trim();
            }
          });

          $("body").delegate("[lay-id='inquiryReviewResultTable'] input[name='discountPrice']", "change", function () {
            if (inquiryReviewResultTableData[$(this).parents("tr").index()]) {
              inquiryReviewResultTableData[$(this).parents("tr").index()].discountPrice = $(this).val().trim();
            }
          });

          $("body").delegate("[lay-id='inquiryReviewResultTable'] input[name='offerRemark']", "change", function () {
            if (inquiryReviewResultTableData[$(this).parents("tr").index()]) {
              inquiryReviewResultTableData[$(this).parents("tr").index()].offerRemark = $(this).val().trim();
            }
          });

          // 保存

          form.on("submit(inquiryOrderReviewSubmit)", function (d) {
            inquiryReviewResultTableData[0].id = data.id;
            layer.load(2);
            admin.req(
              "enterprise/sell/admin/orderPro/update",
              JSON.stringify(inquiryReviewResultTableData[0]),
              function (res) {
                layer.closeAll("loading");
                if (res.code == 200) {
                  layer.msg(res.msg, { icon: 1 });
                  InquiryOrderDetailsFormData.orderProList.forEach(function (item) {
                    if (item.id == data.id) {
                      item.finalResult = inquiryReviewResultTableData[0].finalResult;
                      table.reload("inquiryOrderDetailsTable", { data: InquiryOrderDetailsFormData.orderProList });
                    }
                  });
                  table.reload("orderTable");
                  layer.close(inquiryOrderReviewPop);
                } else {
                  layer.msg(res.msg, { icon: 2 });
                }
              },
              "PUT",
              true,
              "application/json; charset=utf-8"
            );
            return false;
          });
        }
      });
    }

    //询价订单 报价
    function showInquiryOrderOfferForm(data, _type) {
      admin.open({
        type: 1,
        area: ["1500px", "800px"],
        offset: "65px",
        title: "订单报价界面",
        content: $("#inquiryOrderOfferForm").html(),
        success: function () {
          //   请求所属部门
          admin.reqSync(
            "user/admin/user/getUserInfoByUserId",
            { userId: data.creator },
            (res) => {
              if (res.code === 200) {
                InquiryOrderDetailsFormData.departmentName = res.data.departmentName;
              }
            },
            "get"
          );

          form.val("inquiryOrderOfferForm", InquiryOrderDetailsFormData);
          let inquiryOrderOffer = [];
          data.orderProList.forEach((item, index) => {
            if (item.offerStatus == "wait") {
              inquiryOrderOffer.push(item);
            }
          });
          let inquiryOrderOfferTb = table.render({
            elem: "#inquiryOrderOfferTable",
            data: inquiryOrderOffer,
            page: false,
            cellMinWidth: 100,
            cols: [
              [
                { type: "checkbox" },
                { type: "numbers", title: "序号" },
                { field: "customerSkuItem", title: "客户物料编号" },
                { field: "customerSpecCode", title: "客户规格码" },
                { field: "proUnitName", title: "单位" },
                { field: "quantity", title: "数量" },
                { field: "suggestLowestPrice", title: "建议最低单价" },
                { field: "suggestPrice", title: "建议单价" },
                { field: "offerStatusDesc", title: "状态" },
                {
                  field: "offerMoney",
                  title: "最新报价",
                  templet: (d) => '<input type="text" name="offerMoney" class="layui-input">'
                },
                {
                  field: "remark",
                  title: "报价备注",
                  templet: (d) => '<input type="text" name="remark" class="layui-input">'
                }
              ]
            ],
            done: function (res, curr, count) {}
          });

          $("body").delegate("[lay-id='inquiryOrderOfferTable'] input[name='offerMoney']", "change", function () {
            if (inquiryOrderOffer[$(this).parents("tr").index()]) {
              inquiryOrderOffer[$(this).parents("tr").index()].offerMoney = $(this).val().trim();
            }
          });

          $("body").delegate("[lay-id='inquiryOrderOfferTable'] input[name='remark']", "change", function () {
            if (inquiryOrderOffer[$(this).parents("tr").index()]) {
              inquiryOrderOffer[$(this).parents("tr").index()].remark = $(this).val().trim();
            }
          });

          form.on("submit(inquiryOrderOfferSubmit)", function (d) {
            let objData = {},
              objDataList = [];
            let checkStatus = table.checkStatus("inquiryOrderOfferTable");
            new Promise((resolve, reject) => {
              if (checkStatus.data.length > 0) {
                checkStatus.data.forEach((item, index) => {
                  objDataList[index] = {};
                  objDataList[index].offerMoney = item.offerMoney;
                  objDataList[index].remark = item.remark;
                  objDataList[index].proId = item.id;
                });
                resolve(objDataList);
              } else {
                layer.msg("请选择报价物料", { icon: 2 });
              }
            }).then((r) => {
              objData.orderId = data.id;
              objData.orderOfferDetailList = r;
              layer.load(2);
              admin.req(
                "enterprise/sell/admin/orderOffer/add",
                JSON.stringify(objData),
                function (res) {
                  layer.closeAll("loading");
                  if (res.code == 200) {
                    layer.msg(res.msg, { icon: 1 });
                    table.reload("orderTable");
                    layer.closeAll("page");
                  } else {
                    layer.msg(res.msg, { icon: 2 });
                  }
                },
                "POST",
                true,
                "application/json; charset=utf-8"
              );
            });
            return false;
          });
        }
      });
    }

    //询价订单 报价记录
    function showInquiryOrderQuotationRecordForm(data) {
      admin.open({
        type: 1,
        area: ["1500px", "800px"],
        offset: "65px",
        title: "订单报价记录界面",
        content: $("#inquiryOrderQuotationRecordForm").html(),
        success: function () {
          //   请求所属部门
          admin.reqSync(
            "user/admin/user/getUserInfoByUserId",
            { userId: data.creator },
            (res) => {
              if (res.code === 200) {
                InquiryOrderDetailsFormData.departmentName = res.data.departmentName;
              }
            },
            "get"
          );
          form.val("inquiryOrderQuotationRecordForm", InquiryOrderDetailsFormData);

          let inquiryOrderQuotationRecordTb = table.render({
            elem: "#inquiryOrderQuotationRecordTable",
            url: config.base + "enterprise/sell/admin/orderOffer/list?orderId=" + data.id,
            page: false,
            cellMinWidth: 100,
            cols: [
              [
                { field: "code", title: "报价记录编号" },
                { field: "creatorName", title: "报价人" },
                { field: "roleName", title: "所属岗位" },
                { field: "deptName", title: "所属部门" },
                { field: "createTime", title: "报价时间" },
                { field: "proNum", title: "报价物料数" },
                { field: "totalMoney", title: "报价单总金额" },
                { field: "remark", title: "报价备注" },
                { field: "updateDuring", title: "更新时长" },
                { toolbar: "#inquiryOrderQuotationRecordBar", title: "操作" }
              ]
            ],
            done: function (res, curr, count) {}
          });

          table.on("tool(inquiryOrderQuotationRecordTable)", function (obj) {
            let data = obj.data;
            if (obj.event === "" + "" + "") {
              //详情
              showInquiryOrderQuotationRecordDetailsForm(data);
            } else if (obj.event === "final") {
              doFinal(data);
            }
          });
        }
      });
    }

    // 设为终版
    function doFinal(data) {
      layer.confirm(
        "确定设为终版吗？",
        {
          offset: "65px",
          skin: "layui-layer-admin"
        },
        function (i) {
          layer.close(i);
          layer.load(2);
          admin.req(
            "enterprise/sell/admin/orderOffer/finalEdition",
            { id: data.id },
            function (res) {
              layer.closeAll("loading");
              if (res.code == 200) {
                layer.msg(res.msg, { icon: 1 });
                table.reload("inquiryOrderQuotationRecordTable");
                table.reload("orderTable");
              } else {
                layer.msg(res.msg, { icon: 2 });
              }
            },
            "POST"
          );
        }
      );
    }

    //询价订单 报价记录 详情
    function showInquiryOrderQuotationRecordDetailsForm(data) {
      let inquiryOrderQuotationRecordDetailsPop = admin.open({
        type: 1,
        area: ["1450px", "750px"],
        offset: "85px",
        title: "订单报价记录详情界面",
        content: $("#inquiryOrderQuotationRecordDetailsForm").html(),
        success: function () {
          let inquiryOrderQuotationRecordDetailsTableData = [];
          form.val("inquiryOrderQuotationRecordDetailsForm", InquiryOrderDetailsFormData);
          admin.reqSync(
            "enterprise/sell/admin/orderOfferDetail/list",
            { offerId: data.id },
            (res) => {
              if (res.code === 200) {
                inquiryOrderQuotationRecordDetailsTableData = res.data;
              }
            },
            "get"
          );
          let inquiryOrderQuotationRecordDetailsTb = table.render({
            elem: "#inquiryOrderQuotationRecordDetailsTable",
            data: inquiryOrderQuotationRecordDetailsTableData,
            page: false,
            cellMinWidth: 100,
            cols: [
              [
                { type: "numbers", title: "序号" },
                { field: "customerSkuItem", title: "客户物料编号" },
                { field: "customerSpecCode", title: "客户规格码" },
                { field: "unitName", title: "单位" },
                { field: "quantity", title: "数量" },
                { field: "suggestLowestPrice", title: "建议最低单价" },
                { field: "suggestPrice", title: "建议单价" },
                { field: "discountPrice", title: "优惠单价" },
                { field: "statusDesc", title: "状态" },
                { field: "lastMoney", title: "上次报价" },
                {
                  field: "offerMoney",
                  title: "报价",
                  templet: (d) => {
                    if (!data.whetherFinal) {
                      return '<input type="text" name="offerMoney" class="layui-input" value="' + d.offerMoney + '" lay-verify="number">';
                    } else {
                      return d.offerMoney;
                    }
                  }
                },
                {
                  field: "remark",
                  title: "报价备注",
                  templet: (d) => {
                    if (!data.whetherFinal) {
                      return '<input type="text" name="remark" class="layui-input" value="' + d.remark + '">';
                    } else {
                      return d.remark;
                    }
                  }
                }
              ]
            ],
            done: function (res, curr, count) {}
          });

          $("body").delegate("[lay-id='inquiryOrderQuotationRecordDetailsTable'] input[name='offerMoney']", "change", function () {
            if (inquiryOrderQuotationRecordDetailsTableData[$(this).parents("tr").index()]) {
              inquiryOrderQuotationRecordDetailsTableData[$(this).parents("tr").index()].offerMoney = $(this).val().trim();
            }
          });

          $("body").delegate("[lay-id='inquiryOrderQuotationRecordDetailsTable'] input[name='remark']", "change", function () {
            if (inquiryOrderQuotationRecordDetailsTableData[$(this).parents("tr").index()]) {
              inquiryOrderQuotationRecordDetailsTableData[$(this).parents("tr").index()].remark = $(this).val().trim();
            }
          });
          if (data.whetherFinal) {
            $('button[lay-filter="inquiryOrderQuotationRecordDetailsSubmit"]').hide();
          }

          form.on("submit(inquiryOrderQuotationRecordDetailsSubmit)", function (d) {
            let objData = {},
              objDataList = [];
            new Promise((resolve, reject) => {
              inquiryOrderQuotationRecordDetailsTableData.forEach((item, index) => {
                objDataList[index] = {};
                objDataList[index].offerMoney = item.offerMoney;
                objDataList[index].remark = item.remark;
                objDataList[index].id = item.id;
                objDataList[index].proId = item.proId;
              });
              resolve(objDataList);
            }).then((r) => {
              objData.id = data.id;
              objData.orderOfferDetailList = r;
              layer.load(2);
              admin.req(
                "enterprise/sell/admin/orderOffer/update ",
                JSON.stringify(objData),
                function (res) {
                  layer.closeAll("loading");
                  if (res.code == 200) {
                    layer.msg(res.msg, { icon: 1 });
                    table.reload("inquiryOrderQuotationRecordTable");
                    layer.close(inquiryOrderQuotationRecordDetailsPop);
                  } else {
                    layer.msg(res.msg, { icon: 2 });
                  }
                },
                "put",
                true,
                "application/json; charset=utf-8"
              );
            });
            return false;
          });
        }
      });
    }

    // 合同
    function showInquiryOrderContractForm(data) {
      let inquiryOrderQuotationRecordDetailsPop = admin.open({
        type: 1,
        area: ["1500px", "800px"],
        offset: "85px",
        title: "订单合同",
        content: $("#inquiryOrderContractForm").html(),
        success: function () {
          let inquiryOrderContractFormTb = table.render({
            elem: "#inquiryOrderContractFormTable",
            url: config.base + "enterprise/sell/admin/customerContract/list?subjectId=" + data.customerId,
            page: true,
            cellMinWidth: 100,
            cols: [
              [
                { type: "numbers", title: "序号" },
                { field: "code", title: "合同编号" },
                { field: "typeDesc", title: "合同主体类型" },
                { field: "", title: "关联订单数" },
                { field: "companyName", title: "供应商名称" },
                { field: "contractCategoryName", title: "合同分类" },
                { field: "createTime", title: "创建时间" },
                { field: "contactName", title: "供应商签约人" },
                { field: "amount", title: "签约金额" },
                { field: "attachment", title: "合同附件", toolbar: "#viewAttachmentBar" },
                { field: "statusDesc", title: "合同状态" },
                {
                  field: "",
                  title: "操作",
                  width: "150",
                  templet: (d) => {
                    if (data.contractId == 0) {
                      return '<a class="layui-btn layui-btn-xs" lay-event="preservation">保存</a>';
                    } else {
                      return (
                        '<a class="layui-btn layui-btn-xs" lay-event="view">详情</a> ' + '<a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="changeRecord">变更记录</a>'
                      );
                    }
                  }
                }
              ]
            ],
            done: function (res, curr, count) {
              if (data.contractId == 0) {
                $("#contractBtnAdd").show();
              } else {
                $("#contractBtnAdd").hide();
              }
            },
            parseData: function (res) {
              if (data.contractId == 0) {
                return {
                  code: res.code,
                  count: res.count,
                  currentTotal: res.currentTotal,
                  data: res.data,
                  msg: res.msg,
                  settingTotal: res.settingTotal,
                  totalFlag: res.totalFlag
                };
              } else {
                let resData = [];
                res.data.forEach((item) => {
                  if (item.id == data.contractId) {
                    resData.push(item);
                  }
                });
                return {
                  code: res.code,
                  count: res.count,
                  currentTotal: res.currentTotal,
                  data: resData,
                  msg: res.msg,
                  settingTotal: res.settingTotal,
                  totalFlag: res.totalFlag
                };
              }
            }
          });

          // 工具条点击事件
          table.on("tool(inquiryOrderContractFormTable)", function (obj) {
            let contractData = obj.data;
            if (obj.event === "viewAttachment") {
              // 查看附件
              showViewAttachmentModel(contractData);
            } else if (obj.event === "preservation") {
              // 保存(绑定合同)
              layer.confirm(
                "确定使用当前合同吗？",
                {
                  offset: "65px",
                  skin: "layui-layer-admin"
                },
                function (i) {
                  layer.close(i);
                  layer.load(2);
                  admin.req(
                    "enterprise/sell/admin/order/update",
                    JSON.stringify({
                      id: data.id,
                      contractId: contractData.id
                    }),
                    function (res) {
                      layer.closeAll("loading");
                      if (res.code == 200) {
                        layer.msg(res.msg, { icon: 1 });
                        data.contractId = contractData.id;
                        if (contractData.status == "hasSign") {
                          admin.req(
                            "enterprise/sell/admin/order/submit",
                            {
                              id: data.id,
                              type: 6
                            },
                            function (res) {
                              if (res.code == 200) {
                                layer.msg(res.msg + ",订单已转为正是订单", { icon: 1 });
                                layer.close(inquiryOrderQuotationRecordDetailsPop);
                                table.reload("inquiryOrderContractFormTable");
                                table.reload("orderTable");
                              }
                            },
                            "POST"
                          );
                        } else {
                          table.reload("inquiryOrderContractFormTable");
                          table.reload("orderTable");
                        }
                      } else {
                        layer.msg(res.msg, { icon: 2 });
                      }
                    },
                    "put",
                    true,
                    "application/json; charset=utf-8"
                  );
                }
              );
            } else if (obj.event === "view") {
              showViewModel(contractData);
            } else if (obj.event === "changeRecord") {
              showChangeRecordModel(contractData);
            }
          });

          $("#contractBtnAdd").click(function () {
            showContractForm(data, "add");
          });
        }
      });
    }

    // 添加合同
    function showContractForm(data, _type, isRefresh) {
      let contractPop = admin.open({
        type: 1,
        area: "800px",
        offset: "65px",
        title: _type == "edit" ? "修改合同" : "添加合同",
        content: $("#contractForm").html(),
        success: function () {
          //自定义验证规则
          form.verify({
            decimal: [/^[0-9]*(\.[0-9]{1,2})?$/, "格式错误"],
            contractCategoryId: function (value) {
              if (value == "") {
                return "请选择合同分类";
              }
            },
            attachment: function (value) {
              if (value == "") {
                return "请上传附件";
              }
            }
          });

          // 获取合同主体类型
          admin.req(
            "enterprise/contract/admin/contractCategory/types",
            {},
            function (res) {
              if (200 == res.code) {
                $.each(res.data, function (index, item) {
                  $("form select[name='type']").append(new Option(item.name, item.id)); //往下拉菜单里添加元素
                });
                $("form select[name='type']")
                  .find("option")
                  .each(function (index, item) {
                    // 默认主体类型为供应商
                    if ($(item).val() == "client") {
                      $(item).attr("selected", true);
                    }
                  });
                form.render(); //菜单渲染 把内容加载进去
              } else {
                layer.msg("获取合同主体类型失败!", { icon: 2, time: 1000 });
              }
            },
            "GET"
          );

          var selectId = null;
          if (_type == "edit") {
            if (data && data.contractCategoryId) {
              selectId = data.contractCategoryId;
            }
          }

          // 获取合同分类
          admin.req(
            "enterprise/contract/admin/contractCategory/getTreeData",
            {
              selectId: selectId,
              type: "client"
            },
            function (res) {
              if (200 == res.code) {
                xmSelect.render({
                  el: "#selectContractCategory",
                  model: { label: { type: "text" } },
                  radio: true,
                  clickClose: true,
                  filterable: true,
                  tree: {
                    show: true,
                    strict: false,
                    /*expandedKeys: [-1],*/
                    expandedKeys: true
                  },
                  tips: "顶级分类",
                  height: "auto",
                  data() {
                    return res.data;
                  },
                  on: function (data) {
                    //被选中的select的id,如果没有 -1
                    let contractCategoryId = data.arr.length > 0 ? data.change[0].value : "";
                    $("input[name='contractCategoryId']").val(contractCategoryId);
                  }
                });
              } else {
                layer.msg("获取合同分类失败!", { icon: 2, time: 1000 });
              }
            },
            "GET"
          );

          // 获取签约主体
          $("form select[name='subjectId']").append(new Option(data.customerName, data.customerId));

          // 获取客户签约人
          admin.req(
            "enterprise/sell/admin/contactInfo/list",
            {
              limit: 99999,
              selCustomerId: data.customerId
            },
            function (res) {
              if (200 == res.code) {
                $("form select[name='contactsId']").html("");
                $("form select[name='contactsId']").append(new Option("请选择客户签约人", "")); //往下拉菜单里添加元素
                $.each(res.data, function (index, item) {
                  $("form select[name='contactsId']").append(new Option(item.name + "(" + item.telephone + ")", item.id)); //往下拉菜单里添加元素
                });
                form.render(); //菜单渲染 把内容加载进去
                if (data && data.contactsId) {
                  form.val("contractForm", data);
                }
              } else {
                layer.msg("获取客户签约人失败!", { icon: 2, time: 1000 });
              }
            },
            "GET"
          );

          // 获取我方签约人
          admin.req(
            "user/admin/user/list",
            { limit: 99999 },
            function (res) {
              if (200 == res.code) {
                $("form select[name='contractor']").append(new Option("请选择我方签约人", "")); //往下拉菜单里添加元素
                $.each(res.data, function (index, item) {
                  $("form select[name='contractor']").append(new Option(item.nickname + "(" + item.username + ")", item.id)); //往下拉菜单里添加元素
                });
                form.render(); //菜单渲染 把内容加载进去
                if (data && data.contractor) {
                  form.val("contractForm", data);
                }
              } else {
                layer.msg("获取我方签约人失败!", { icon: 2, time: 1000 });
              }
            },
            "GET"
          );

          // 获取信息审批人
          admin.req(
            "user/admin/user/list",
            { limit: 99999 },
            function (res) {
              console.log(res.data);
              if (200 == res.code) {
                $("form select[name='approver']").append(new Option("请选择信息审批人", "")); //往下拉菜单里添加元素
                $.each(res.data, function (index, item) {
                  $("form select[name='approver']").append(new Option(item.nickname + "(" + item.username + ")", item.id)); //往下拉菜单里添加元素
                });
                form.render(); //菜单渲染 把内容加载进去
                if (data && data.approver) {
                  form.val("contractForm", data);
                }
              } else {
                layer.msg("获取信息审批人失败!", { icon: 2, time: 1000 });
              }
            },
            "GET"
          );

          // 上传附件
          upload.render({
            elem: "#addDevicePicBtn",
            url: config.upload_url + "uploadFile",
            data: {},
            accept: "file",
            exts: "pdf",
            headers: { Authorization: "Bearer " + config.getToken() },
            done: function (res) {
              if (res.code == 200) {
                layer.msg(res.msg || "上传成功", { icon: 1 });
                let imagUrl = res.data.url;
                var name = res.data.fileName;
                $("#addHeaderImg").html(
                  '<div class="attachments">' + '<div><img src="../../../admin/assets/images/attachmentsIcon/pdf.png"><span class="file-a">' + name + "</span></div></div>"
                );
                $("#attachment").val(imagUrl);

                $(".attachments").click(function () {
                  var json = {};
                  json.attachment = imagUrl;
                  showViewAttachmentModel(json);
                });
              } else if (res.code == 502) {
                return location.replace("admin/login.html");
              } else {
                layer.msg(res.msg || "上传失败", { icon: 2 });
              }
            }
          });
          if (_type == "edit") {
            form.val("contractForm", data);
          }

          // 表单提交事件
          form.on("submit(contractFormSubmit)", function (d) {
            layer.load(2);
            admin.req(
              _type == "edit" ? "enterprise/sell/admin/customerContract/update" : "enterprise/sell/admin/customerContract/add",
              d.field,
              function (res) {
                layer.closeAll("loading");
                if (res.code == 200) {
                  layer.msg(res.msg, { icon: 1 });
                  if (isRefresh) {
                    admin.req(
                      "enterprise/sell/admin/customerContract/list",
                      { subjectId: data.customerId },
                      function (res) {
                        if (res.code == 200) {
                          loadSelectHtml(res.data, "选择合同", "contractId", 3, "inquiryOrderInformationForm");
                        }
                      },
                      "GET"
                    );
                  } else {
                    table.reload("inquiryOrderContractFormTable");
                  }
                  layer.close(contractPop);
                } else {
                  layer.msg(res.msg, { icon: 2 });
                }
              },
              _type == "edit" ? "PUT" : "POST"
            );
            return false;
          });
        }
      });
    }

    // 查看附件
    function showViewAttachmentModel(data) {
      admin.open({
        type: 1,
        area: ["1150px", "700px"],
        offset: "65px",
        title: "查看附件",
        content: $("#viewAttachmentHtml").html(),
        success: function () {
          if (data.attachment) {
            PDFObject.embed(data.attachment, "#example1");
          }
        }
      });
    }

    // 合同详情弹窗
    function showViewModel(data) {
      admin.open({
        type: 1,
        area: ["80%", "80%"],
        offset: "65px",
        title: "合同详情",
        content: $("#contractView").html(),
        success: function () {
          // 查询我方签约人
          admin.req(
            "user/admin/user/list",
            { limit: 99999 },
            function (res) {
              console.log(res.data);
              if (200 == res.code) {
                $.each(res.data, function (index, item) {
                  if (item.id == data.contractor) {
                    $("#contractorName").text("我方签约人：" + item.nickname + "(" + item.username + ")");
                  }
                });
              } else {
                layer.msg("获取我方签约人失败!", { icon: 2, time: 1000 });
              }
            },
            "GET"
          );

          // 查询合同保管员
          admin.req(
            "user/admin/user/list",
            { limit: 99999 },
            function (res) {
              if (200 == res.code) {
                $.each(res.data, function (index, item) {
                  if (item.id == data.keeper) {
                    $("#keeperName").text("合同保管员：" + item.nickname + "(" + item.username + ")");
                  }
                });
              } else {
                layer.msg("获取合同保管员失败!", { icon: 2, time: 1000 });
              }
            },
            "GET"
          );

          // 查询信息审批人
          admin.req(
            "user/admin/user/list",
            { limit: 99999 },
            function (res) {
              if (200 == res.code) {
                $.each(res.data, function (index, item) {
                  if (item.id == data.approver) {
                    $("#approverName").text("信息审批人：" + item.nickname + "(" + item.username + ")");
                  }
                });
              } else {
                layer.msg("获取信息审批人失败!", { icon: 2, time: 1000 });
              }
            },
            "GET"
          );

          $("#attachmentName").text("合同附件：" + data.attachment.substring(data.attachment.lastIndexOf("/") + 1));

          laytpl(contractInfoHtml.innerHTML).render(data, function (html) {
            $("#contractInfo").html(html);
          });

          if (data.attachment) {
            PDFObject.embed(data.attachment, "#exampleView");
          }
        }
      });
    }

    // 合同变更记录
    function showChangeRecordModel(data) {
      var supplierContract = data;
      admin.open({
        type: 1,
        area: ["80%", "80%"],
        offset: "65px",
        title: "合同变更记录",
        content: $("#contractChangeRecord").html(),
        success: function () {
          // 是否显示添加合同变更记录按钮
          isShowAddBtn(supplierContract);

          // 渲染表格
          var changeRecordInsTb = table.render({
            elem: "#contractChangeRecordTable",
            url: config.base + "enterprise/sell/admin/customerContract/contractChangeRecordList",
            where: { contractId: supplierContract.id },
            page: true,
            cellMinWidth: 100,
            cols: [
              [
                { type: "numbers" },
                { field: "code", title: "合同编号", width: 130 },
                { field: "typeDesc", title: "合同主体类型", width: 140 },
                { field: "companyName", title: "客户名称", width: 120 },
                { field: "contractCategoryName", title: "合同分类", width: 120 },
                { field: "createTime", title: "创建时间", width: 170 },
                { field: "contactName", title: "客户签约人", width: 120 },
                { field: "amount", title: "签约金额", width: 110 },
                { field: "attachment", title: "合同附件", width: 110, toolbar: "#viewAttachmentBar" },
                { field: "statusDesc", title: "合同状态", width: 110 },
                { align: "center", toolbar: "#contractChangeRecordTableBar", title: "操作", width: 200 }
              ]
            ],
            done: function (res, curr, count) {}
          });

          // 工具条点击事件
          table.on("tool(contractChangeRecordTable)", function (obj) {
            var data = obj.data;
            if (obj.event === "edit") {
              // 修改
              showEditChangeRecordModel(data, "edit");
            } else if (obj.event === "view") {
              // 详情
              showViewModel(data);
            } else if (obj.event === "audit") {
              // 审核
              showAuditModel(data);
            } else if (obj.event === "final") {
              // 终版
              doFinal(data);
            } else if (obj.event === "viewAttachment") {
              // 查看附件
              showViewAttachmentModel(data);
            }
          });

          // 添加按钮点击事件
          $("#contractChangeRecordBtnAdd").click(function () {
            showEditChangeRecordModel();
          });

          // 显示编辑弹窗
          function showEditChangeRecordModel(data) {
            var contractChangeRecord = admin.open({
              type: 1,
              area: ["800px", "80%"],
              offset: "65px",
              title: data ? "修改合同变更记录" : "添加合同变更记录",
              content: $("#contractChangeRecordForm").html(),
              success: function () {
                //自定义验证规则
                form.verify({
                  decimal: [/^[0-9]*(\.[0-9]{1,2})?$/, "格式错误"],
                  contractCategoryId: function (value) {
                    if (value == "") {
                      return "请选择合同分类";
                    }
                  },
                  attachment: function (value) {
                    if (value == "") {
                      return "请上传附件";
                    }
                  }
                });

                // 签约时间
                laydate.render({
                  elem: "#signingTime",
                  type: "date"
                });

                // 交货时间
                laydate.render({
                  elem: "#deliveryTimeChangeRecord",
                  type: "date"
                });

                var selectId = null;
                if (supplierContract && supplierContract.contractCategoryId) {
                  selectId = supplierContract.contractCategoryId;
                }

                if (data && data.contractCategoryId) {
                  selectId = data.contractCategoryId;
                }

                // 获取合同分类
                admin.req(
                  "enterprise/contract/admin/contractCategory/getTreeData",
                  {
                    selectId: selectId,
                    type: "client"
                  },
                  function (res) {
                    if (200 == res.code) {
                      xmSelect.render({
                        el: "#selectContractCategoryChangeRecord",
                        model: { label: { type: "text" } },
                        radio: true,
                        clickClose: true,
                        filterable: true,
                        tree: {
                          show: true,
                          strict: false,
                          /*expandedKeys: [-1],*/
                          expandedKeys: true
                        },
                        tips: "顶级分类",
                        height: "auto",
                        data() {
                          return res.data;
                        },
                        on: function (data) {
                          //被选中的select的id,如果没有 -1
                          let contractCategoryId = data.arr.length > 0 ? data.change[0].value : "";
                          $("input[name='contractCategoryId']").val(contractCategoryId);
                        }
                      });
                    } else {
                      layer.msg("获取合同分类失败!", { icon: 2, time: 1000 });
                    }
                  },
                  "GET"
                );

                var selCustomerId = null;
                if (supplierContract && supplierContract.subjectId) {
                  selCustomerId = supplierContract.subjectId;
                }
                if (data && data.subjectId) {
                  selCustomerId = data.subjectId;
                }
                if (selCustomerId) {
                  // 获取客户签约人
                  admin.req(
                    "enterprise/sell/admin/contactInfo/list",
                    {
                      limit: 99999,
                      selCustomerId: selCustomerId
                    },
                    function (res) {
                      if (200 == res.code) {
                        $("form select[name='contactsId']").html("");
                        $("form select[name='contactsId']").append(new Option("请选择客户签约人", "")); //往下拉菜单里添加元素
                        $.each(res.data, function (index, item) {
                          $("form select[name='contactsId']").append(new Option(item.name + "(" + item.telephone + ")", item.id)); //往下拉菜单里添加元素
                        });
                        form.render(); //菜单渲染 把内容加载进去
                        if (data && data.contactsId) {
                          form.val("contractChangeRecordForm", data);
                        } else {
                          form.val("contractChangeRecordForm", supplierContract);
                        }
                      } else {
                        layer.msg("获取客户签约人失败!", { icon: 2, time: 1000 });
                      }
                    },
                    "GET"
                  );
                }

                // 获取我方签约人
                admin.req(
                  "user/admin/user/list",
                  { limit: 99999 },
                  function (res) {
                    if (200 == res.code) {
                      $("form select[name='contractor']").append(new Option("请选择我方签约人", "")); //往下拉菜单里添加元素
                      $.each(res.data, function (index, item) {
                        $("form select[name='contractor']").append(new Option(item.nickname + "(" + item.username + ")", item.id)); //往下拉菜单里添加元素
                      });
                      form.render(); //菜单渲染 把内容加载进去
                      if (data && data.contractor) {
                        form.val("contractChangeRecordForm", data);
                      } else {
                        form.val("contractChangeRecordForm", supplierContract);
                      }
                    } else {
                      layer.msg("获取我方签约人失败!", { icon: 2, time: 1000 });
                    }
                  },
                  "GET"
                );

                // 获取信息审批人
                admin.req(
                  "user/admin/user/list",
                  { limit: 99999 },
                  function (res) {
                    if (200 == res.code) {
                      $("form select[name='approver']").append(new Option("请选择信息审批人", "")); //往下拉菜单里添加元素
                      $.each(res.data, function (index, item) {
                        $("form select[name='approver']").append(new Option(item.nickname + "(" + item.username + ")", item.id)); //往下拉菜单里添加元素
                      });
                      form.render(); //菜单渲染 把内容加载进去
                      if (data && data.approver) {
                        form.val("contractChangeRecordForm", data);
                      } else {
                        form.val("contractChangeRecordForm", supplierContract);
                      }
                    } else {
                      layer.msg("获取信息审批人失败!", { icon: 2, time: 1000 });
                    }
                  },
                  "GET"
                );

                // 上传附件
                upload.render({
                  elem: "#addDevicePicBtnChangeRecord",
                  url: config.upload_url + "uploadFile",
                  data: {},
                  accept: "file",
                  exts: "pdf",
                  headers: { Authorization: "Bearer " + config.getToken() },
                  done: function (res) {
                    if (res.code == 200) {
                      layer.msg(res.msg || "上传成功", { icon: 1 });
                      let imagUrl = res.data.url;
                      var name = res.data.fileName;
                      $("#addHeaderImgChangeRecord").html(
                        '<div class="attachments">' + '<div><img src="../../../admin/assets/images/attachmentsIcon/pdf.png"><span class="file-a">' + name + "</span></div></div>"
                      );
                      $("#attachmentChangeRecord").val(imagUrl);

                      $(".attachments").click(function () {
                        var json = {};
                        json.attachment = imagUrl;
                        showViewAttachmentModel(json);
                      });
                    } else if (res.code == 502) {
                      return location.replace("admin/login.html");
                    } else {
                      layer.msg(res.msg || "上传失败", { icon: 2 });
                    }
                  }
                });

                var attachment = "";

                if (supplierContract && supplierContract.attachment) {
                  attachment = supplierContract.attachment;
                }
                if (data && data.attachment) {
                  attachment = data.attachment;
                }

                if (attachment != "") {
                  var name = attachment.substring(attachment.lastIndexOf("/") + 1);
                  // onclick="previewFile(\''+name+'\', \''+attachment+'\')"
                  $("#addHeaderImgChangeRecord").html(
                    '<div class="attachments">' + '<div><img src="../../../admin/assets/images/attachmentsIcon/pdf.png"><span class="file-a">' + name + "</span></div></div>"
                  );
                  $("#attachmentChangeRecord").val(attachment);

                  $(".attachments").click(function () {
                    var json = {};
                    json.attachment = attachment;
                    showViewAttachmentModel(json);
                  });
                }

                // 获取合同保管员
                admin.req(
                  "user/admin/user/list",
                  { limit: 99999 },
                  function (res) {
                    if (200 == res.code) {
                      $("form select[name='keeper']").append(new Option("请选择合同保管员", "")); //往下拉菜单里添加元素
                      $.each(res.data, function (index, item) {
                        $("form select[name='keeper']").append(new Option(item.nickname + "(" + item.username + ")", item.id)); //往下拉菜单里添加元素
                      });
                      form.render(); //菜单渲染 把内容加载进去
                      if (data && data.keeper) {
                        form.val("contractChangeRecordForm", data);
                      }
                    } else {
                      layer.msg("获取合同保管员失败!", { icon: 2, time: 1000 });
                    }
                  },
                  "GET"
                );

                form.on("switch(isFinal)", function (obj) {
                  if (obj.elem.checked) {
                    $("#content").show();
                    $("#deliveryTimeChangeRecord").attr("lay-verify", "required").attr("required");
                    $("input[name='address']").attr("lay-verify", "required").attr("required", true);
                    $("select[name='keeper']").attr("lay-verify", "required").attr("required", true).attr("lay-search", true);
                    form.render();
                  } else {
                    $("#content").hide();
                    $("#deliveryTimeChangeRecord").removeAttr("lay-verify");
                    $("input[name='address']").removeAttr("lay-verify");
                    $("select[name='keeper']").removeAttr("lay-verify");
                  }
                });

                if (data) {
                  form.val("contractChangeRecordForm", data);
                } else {
                  form.val("contractChangeRecordForm", supplierContract);
                }
                // 表单提交事件
                form.on("submit(contractChangeRecordFormSubmit)", function (d) {
                  layer.load(2);
                  var isFinal = $("form input[name='isFinal']").prop("checked");
                  if (!isFinal) {
                    d.field.isFinal = false;
                  } else {
                    d.field.isFinal = true;
                  }
                  if (d.field.signingTime) {
                    d.field.signingTime = d.field.signingTime + " 00:00:00";
                  }
                  if (d.field.deliveryTime) {
                    d.field.deliveryTime = d.field.deliveryTime + " 00:00:00";
                  }
                  d.field.contractId = supplierContract.id;
                  admin.req(
                    data ? "enterprise/sell/admin/customerContract/updateContractChangeRecord" : "enterprise/sell/admin/customerContract/addContractChangeRecord",
                    d.field,
                    function (res) {
                      layer.closeAll("loading");
                      if (res.code == 200) {
                        layer.msg(res.msg, { icon: 1 });
                        isShowAddBtn(supplierContract);
                        table.reload("contractChangeRecordTable");
                        layer.close(contractChangeRecord);
                      } else {
                        layer.msg(res.msg, { icon: 2 });
                      }
                    },
                    data ? "PUT" : "POST"
                  );
                  return false;
                });
              }
            });
          }

          // 显示审核弹窗
          function showAuditModel(data) {
            var contractAudit = admin.open({
              type: 1,
              area: ["80%", "80%"],
              offset: "65px",
              title: "合同审核",
              content: $("#contractAuditForm").html(),
              success: function () {
                // 查询我方签约人
                admin.req(
                  "user/admin/user/list",
                  { limit: 99999 },
                  function (res) {
                    if (200 == res.code) {
                      $.each(res.data, function (index, item) {
                        if (item.id == data.contractor) {
                          $("#contractorName").text("我方签约人：" + item.nickname + "(" + item.username + ")");
                        }
                      });
                    } else {
                      layer.msg("获取我方签约人失败!", { icon: 2, time: 1000 });
                    }
                  },
                  "GET"
                );

                // 查询合同保管员
                admin.req(
                  "user/admin/user/list",
                  { limit: 99999 },
                  function (res) {
                    if (200 == res.code) {
                      $.each(res.data, function (index, item) {
                        if (item.id == data.keeper) {
                          $("#keeperName").text("合同保管员：" + item.nickname + "(" + item.username + ")");
                        }
                      });
                    } else {
                      layer.msg("获取合同保管员失败!", { icon: 2, time: 1000 });
                    }
                  },
                  "GET"
                );

                // 查询信息审批人
                admin.req(
                  "user/admin/user/list",
                  { limit: 99999 },
                  function (res) {
                    if (200 == res.code) {
                      $.each(res.data, function (index, item) {
                        if (item.id == data.approver) {
                          $("#approverName").text("信息审批人：" + item.nickname + "(" + item.username + ")");
                        }
                      });
                    } else {
                      layer.msg("获取信息审批人失败!", { icon: 2, time: 1000 });
                    }
                  },
                  "GET"
                );

                $("#attachmentNameAudit").text("合同附件：" + data.attachment.substring(data.attachment.lastIndexOf("/") + 1));

                laytpl(contractInfoHtml.innerHTML).render(data, function (html) {
                  $("#contractInfoAudit").html(html);
                });

                if (data.attachment) {
                  PDFObject.embed(data.attachment, "#example1Audit");
                }

                form.val("contractAuditForm", data);

                // 表单提交事件
                form.on("submit(contractAuditFormSubmit)", function (d) {
                  layer.load(2);
                  d.field.status = $(this).data("status");
                  admin.req(
                    "enterprise/sell/admin/customerContract/auditContractChangeRecord",
                    d.field,
                    function (res) {
                      layer.closeAll("loading");
                      if (res.code == 200) {
                        layer.msg(res.msg, { icon: 1 });
                        isShowAddBtn(supplierContract);
                        table.reload("contractChangeRecordTable");
                        layer.close(contractAudit);
                      } else {
                        layer.msg(res.msg, { icon: 2 });
                      }
                    },
                    "POST"
                  );
                  return false;
                });
              }
            });
          }

          // 终版
          function doFinal(data) {
            var contractFinal = admin.open({
              type: 1,
              area: ["800px"],
              offset: "65px",
              title: "合同终版确认",
              content: $("#contractFinalForm").html(),
              success: function () {
                // 交货时间
                laydate.render({
                  elem: "#deliveryTimeFina",
                  type: "date"
                });

                // 获取合同保管员
                admin.req(
                  "user/admin/user/list",
                  { limit: 99999 },
                  function (res) {
                    if (200 == res.code) {
                      $("form select[name='keeper']").append(new Option("请选择合同保管员", "")); //往下拉菜单里添加元素
                      $.each(res.data, function (index, item) {
                        $("form select[name='keeper']").append(new Option(item.nickname + "(" + item.username + ")", item.id)); //往下拉菜单里添加元素
                      });
                      form.render(); //菜单渲染 把内容加载进去
                    } else {
                      layer.msg("获取合同保管员失败!", { icon: 2, time: 1000 });
                    }
                  },
                  "GET"
                );

                form.val("contractFinalForm", data);

                // 表单提交事件
                form.on("submit(contractFinalFormSubmit)", function (d) {
                  layer.load(2);
                  if (d.field.deliveryTime) {
                    d.field.deliveryTime = d.field.deliveryTime + " 00:00:00";
                  }
                  admin.req(
                    "enterprise/sell/admin/customerContract/setContractFinal",
                    d.field,
                    function (res) {
                      layer.closeAll("loading");
                      if (res.code == 200) {
                        layer.msg(res.msg, { icon: 1 });
                        isShowAddBtn(supplierContract);
                        table.reload("contractChangeRecordTable");
                        table.reload("contractTable");
                        layer.close(contractFinal);
                        admin.req(
                          "enterprise/sell/admin/order/submit",
                          {
                            id: InquiryOrderDetailsFormData.id,
                            type: 6
                          },
                          function (res) {
                            if (res.code == 200) {
                              layer.msg(res.msg + ",订单已转为正是订单", { icon: 1 });
                              layer.closeAll("page");
                              table.reload("orderTable");
                            }
                          },
                          "POST"
                        );
                      } else {
                        layer.msg(res.msg, { icon: 2 });
                      }
                    },
                    "POST"
                  );
                  return false;
                });
              }
            });
          }
        }
      });
    }

    // 是否显示添加合同变更记录按钮
    function isShowAddBtn(data) {
      admin.req(
        "enterprise/sell/admin/customerContract/isShowAddBtn",
        { id: data.id },
        function (res) {
          if (200 == res.code) {
            if (res.data) {
              $("#contractChangeRecordBtnAdd").show();
            } else {
              $("#contractChangeRecordBtnAdd").hide();
            }
          }
        },
        "GET"
      );
    }
  });
</script>
